namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Drawing;

    public class FormDmNhTsLister : FormListLister
    {
        private IContainer components;
        private bool ib_CheckEdited;
        private string is_FixedAssetType = "C";

        public FormDmNhTsLister()
        {
            this.ChildFirstFilter = "Loai_Ts = 'C'";
            this.InitializeComponent();
        }

        public FormDmNhTsLister(string NhLoai3)
        {            
            this.InitializeComponent();
            if (NhLoai3.Equals("CC"))
            {
                this.ChildFirstFilter = "Loai_Ts = 'K'";
                this.is_FixedAssetType = "K";
                this.Text = "Danh mục nhóm công cụ";
                OnRefresh();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // FormDmNhTsLister
            // 
            this.ClientSize = new System.Drawing.Size(786, 528);
            this.LocalFieldCount = 0;
            this.LocalFieldName = "MA_NH_TS";
            this.LocalTableName = "DMNHTS";
            this.Name = "FormDmNhTsLister";
            this.OrderFieldNames = "STT_NH_TS";
            this.RefreshAfterChanged = true;
            this.SortByColumn = false;
            this.Text = "Danh mục nhóm tài sản";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public override bool OnAdd()
        {
            base.LocalFormEditor = new FormDmNhTsEditor(is_FixedAssetType.Equals("C") ? "TS" : "CC");
            return base.OnAdd();
        }

        public override bool OnEdit()
        {
            base.LocalFormEditor = new FormDmNhTsEditor(is_FixedAssetType.Equals("C") ? "TS" : "CC");
            return base.OnEdit();
        }

        public override void OnFillData()
        {
            object[][] objArray = new object[5][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Ma_Nh_Ts";
            objArray2[1] = "Mã nhóm";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Ten_Nh_Ts";
            objArray3[1] = "Tên nhóm";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "Nh_Me_Ts";
            objArray4[1] = "Nhóm mẹ";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            objArray[3] = new object[] { "Bac_Nh_Ts", "Cấp", "N", AppInstance.TextNumericFormat.None };
            object[] objArray6 = new object[4];
            objArray6[0] = "Nh_Cuoi_Ts";
            objArray6[1] = "Nhóm cuối";
            objArray6[2] = "C";
            objArray[4] = objArray6;
            base.ColNames = objArray;
            base.OnFillData();
        }

        public override void OnRefresh()
        {
            base.LocalDataSet = new System.Data.DataSet("VBSP");
            base.LocalDataSet.Tables.Add(new DmNhTsDataAccess().GetDataTable(is_FixedAssetType.Equals("C") ? "TS" : "CC"));
            base.OnRefresh();
        }

        protected override void OnShowChildForm()
        {
            if (this.IsContainChilds)
            {
                FormDmTsLister lister = new FormDmTsLister(this);
                lister.FixedAssetType = this.FixedAssetType;
                lister.CheckEdited = this.CheckEdited;
                lister.CurrentCode = base.ChildItemCode;
                base.ChildFormLister = lister;
                lister.FirstFilter = base.ChildFirstFilter;
                lister.ShowDialog();
                if (!lister.EscapeKeyHook)
                {
                    base.Close();
                }
            }
        }

        protected override void OnShowChildForm(string ps_ChildItemCode)
        {
            FormDmTsLister lister = new FormDmTsLister(this);
            lister.FixedAssetType = this.FixedAssetType;
            lister.CheckEdited = this.CheckEdited;
            lister.CurrentCode = ps_ChildItemCode;
            if (lister.LocalCurrentRow != null)
            {
                base.ChildFormLister = lister;
                lister.FirstFilter = base.ChildFirstFilter;
                lister.ShowDialog();
            }
        }

        public bool CheckEdited
        {
            get
            {
                return this.ib_CheckEdited;
            }
            set
            {
                this.ib_CheckEdited = value;
            }
        }

        public string FixedAssetType
        {
            get
            {
                return this.is_FixedAssetType;
            }
            set
            {
                this.is_FixedAssetType = value;
            }
        }

        protected override bool IsContainChilds
        {
            get
            {
                return ((base.LocalCurrentRow != null) && base.LocalCurrentRow["Nh_Cuoi_Ts"].ToString().Equals("C"));
            }
        }
    }
}

